/**
 * @author: 小佘佘🦀
 * @description: 上传图片
 * @param {File} file
 * 
 * */

import { resetState } from "@/lib/store";
import { redirect } from "next/navigation";
import toast from "react-hot-toast";

 

// 导出一个异步函数getFlags，用于获取标志
export const uploadFileImage = async (file: File) => {

    const formData = new FormData();
    formData.append('clockfile', file);
    

    const response = await fetch(`/api-backend/api/flag/upload`, {
        method: "post",
        mode: "no-cors",
        body: formData,
        redirect: "manual" 
    })

    if(!response.ok){
        toast.dismiss()
        toast.error("未授权请重新登录")
        resetState()
        return redirect('/login')
    }

    // 返回标志
    return response
}